<?php

namespace App\Models;


use App\Tool\Helper;

/**
 * App\Models\OcrThen
 *
 * @property int $id
 * @property int|null $ocr_id 化验单id
 * @property int|null $user_id 用户id
 * @property string|null $character 性状（Character）
 * @property string|null $color 颜色（Color）
 * @property string|null $ob 隐血（OB）
 * @property string|null $nyl 粘液（NY1）
 * @property string|null $wbc 白细胞（WBC）
 * @property string|null $rbc 红细胞（RBC）
 * @property string|null $pyocyte 脓细胞（Pyocyte）
 * @property string|null $btsxb 吞噬细胞（BTSXB）
 * @property string|null $hcl 蛔虫卵（HCL）
 * @property string|null $gcl 钩虫卵（GCL）
 * @property string|null $ncl 蛲虫卵（NCL）
 * @property string|null $bcl 鞭虫卵（BCL）
 * @property string|null $xxcl 血吸虫卵（XXCL）
 * @property string|null $gxcl 肝吸虫卵（GXCL）
 * @property string|null $cdc 肠滴虫（CDC）
 * @property string|null $dfkl 淀粉颗粒（DFKL）
 * @property string|null $fatty_oils 脂肪滴（Fatty oils）
 * @property string|null $other 其他（other）
 * @property string|null $rota_v 快速轮状病毒鉴定（ROTA.V）
 * @property string|null $xbd 腺病毒抗原（XBD）
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen query()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereBcl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereBtsxb($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereCdc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereCharacter($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereColor($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereDfkl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereFattyOils($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereGcl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereGxcl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereHcl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereNcl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereNyl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereOb($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereOcrId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereOther($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen wherePyocyte($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereRbc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereRotaV($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereWbc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereXbd($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrThen whereXxcl($value)
 * @mixin \Eloquent
 */
class OcrThen extends Base{

    protected $table = 'ocr_then';
    public $columnsArr = [
        'character' => '性状（Character）',
        'color' => '颜色（Color）',
        'ob' => '隐血（OB）',
        'nyl' => '粘液（NY1）',
        'wbc' => '白细胞（WBC）',
        'rbc' => '红细胞（RBC）',
        'pyocyte' => '脓细胞（Pyocyte）',
        'btsxb' => '吞噬细胞（BTSXB）',
        'hcl' => '蛔虫卵（HCL）',
        'gcl' => '钩虫卵（GCL）',
        'ncl' => '蛲虫卵（NCL）',
        'bcl' => '鞭虫卵（BCL）',
        'xxcl' => '血吸虫卵（XXCL）',
        'gxcl' => '肝吸虫卵（GXCL）',
        'cdc' => '肠滴虫（CDC）',
        'dfkl' => '淀粉颗粒（DFKL）',
        'fatty_oils' => '脂肪滴（Fatty oils）',
        'other' => '其他（other）',
        'rota_v' => '快速轮状病毒鉴定（ROTA.V）',
        'xbd' => '腺病毒抗原（XBD）',
    ];

    protected $fillable = [
    ];

//    public $timestamps = false;//关闭自动维护

    public function add($item)
    {
        $columnsArr = Helper::reverseArr($this->columnsArr);
        $insertItem = [];
        foreach ($item as $k => $value) {
            $insertItem[$columnsArr[$value['name']] ?? $value['name']] = $value['content'];
        }
        $insertItem['created_at'] = date('Y-m-d H:i:s');
        $insertItem['updated_at'] = $insertItem['created_at'];

        self::insert($insertItem);
    }

    /**
     * 编辑资料
     *
     * @param $id
     * @param $user_id
     * @param $data
     * @return false
     */
    public function edit($id, $user_id, $data)
    {
        $model = self::whereUserId($user_id)
            ->where('id', $id)
            ->first();
        if (empty($model)) return false;

        $model->character = $data['character'] ?? null;
        $model->color = $data['color'] ?? null;
        $model->ob = $data['ob'] ?? null;
        $model->nyl = $data['nyl'] ?? null;
        $model->wbc = $data['wbc'] ?? null;
        $model->rbc = $data['rbc'] ?? null;
        $model->pyocyte = $data['pyocyte'] ?? null;
        $model->btsxb = $data['btsxb'] ?? null;
        $model->hcl = $data['hcl'] ?? null;
        $model->gcl = $data['gcl'] ?? null;
        $model->ncl = $data['ncl'] ?? null;
        $model->bcl = $data['bcl'] ?? null;
        $model->xxcl = $data['xxcl'] ?? null;
        $model->gxcl = $data['gxcl'] ?? null;
        $model->cdc = $data['cdc'] ?? null;
        $model->dfkl = $data['dfkl'] ?? null;
        $model->fatty_oils = $data['fatty_oils'] ?? null;
        $model->other = $data['other'] ?? null;
        $model->rota_v = $data['rota_v'] ?? null;
        $model->xbd = $data['xbd'] ?? null;
        return $model->save();
    }
}
